﻿using System;
using System.Collections.Generic;

namespace NRehersal
{
    public abstract class RehersalBase:IDisposable
    {
        protected internal Action onceBeforeEachTest=delegate {  };
        protected internal Action onceAfterEachTest = delegate { };
        protected internal Action onceBeforeAllTests = delegate { };
        protected internal Action onceAfterAllTests = delegate { };

        private TestRunner runner;

        static RehersalBase()
        {
            
        }

        protected RehersalBase()
        {
            TestOverrides.TestDataFactory = this.TestDataFactory;
                runner = new TestRunner(this);
        }

        internal List<TestData> Tests = new List<TestData>();
        public abstract void TheTests();

        protected ITestInvocation TEST(string name, Action code)
        {
            TestData data = new TestData(code,name);
            data = TestOverrides.TestDataFactory(data);
            Tests.Add(data);
            return new TestExpectationState(data);
        }

        private TestData TestDataFactory(TestData data)
        {
            //can be extended by the end user by replacing the delegate in TestFrameworkExtensions
            return data;
        }

        protected ITestInvocation TEST(string name)
        {
            return TEST(name, null);
        }

        public void Dispose()
        {
            runner.RunTests();
        }
    }
}
